package com.monkeygroup.mygoplus.base;

import android.graphics.Rect;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.WindowManager;

import com.monkeygroup.mygoplus.MyGoApplication;
import com.monkeygroup.mygoplus.R;

public abstract class BaseActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //透明状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        setContentView();
        initView();
        setTitle();
        setListener();

        doEvent();
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        if (MyGoApplication.statusHight == 0) {
            Rect outRect = new Rect();
            getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
            MyGoApplication.statusHight = outRect.top;

            setTitle();
        }

    }

    /**
     * 设置标题上下padding，沉浸式标题UI
     **/
    public void setTitle() {
        if (MyGoApplication.statusHight != 0) {
            findViewById(R.id.layout_title).setPadding(0, MyGoApplication.statusHight, 0, 0);
        } else {
            findViewById(R.id.layout_title).setPadding(0, 40, 0, 0);
        }
    }

    /**
     * 设置整体的布局VIEW
     **/
    public abstract void setContentView();

    /**
     * 初始化VIEW
     **/
    public abstract void initView();

    /**
     * 处理监听
     **/
    public abstract void setListener();

    /**
     * 处理数据、网络请求和逻辑事件
     **/
    public abstract void doEvent();
}
